
package br.unipampa.view;

import br.unipampa.model.Data;
import br.unipampa.utilitarios.ExecutaSom;
import br.unipampa.utilitarios.ImplementaIcone;
import br.unipampa.utilitarios.TrataAlarme;
import br.unipampa.utilitarios.VerificarCampos;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author Gabriel Moro
 * @since 15/03/2013
 * @version 1.2
 */
public class EdicaoDeCompromisso extends javax.swing.JFrame implements VerificarCampos, ImplementaIcone,EfeitosSonoros{

    private Data date;
    private Image iconeTitulo;

    /**
     * Creates new form FormularioPrincipal
     */
    public EdicaoDeCompromisso() {

        initComponents();



        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                ApoioDeInterface.mensagemSair();
            }
        });

        tratarIcone();
        
        setResizable(false);
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnVoltar = new javax.swing.JButton();
        jPanelInterno = new javax.swing.JPanel();
        lblCompromisso = new javax.swing.JLabel();
        txtCompromisso = new javax.swing.JTextField();
        lblDia = new javax.swing.JLabel();
        lblHora = new javax.swing.JLabel();
        lblAno = new javax.swing.JLabel();
        btnSalvar = new javax.swing.JButton();
        lblMes = new javax.swing.JLabel();
        lblRecebeHora = new javax.swing.JLabel();
        lblRecebeAno = new javax.swing.JLabel();
        lblRecebeDia = new javax.swing.JLabel();
        lblRecebeMes = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Edição de Compromisso");

        btnVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unipampa/icons/voltar.png"))); // NOI18N
        btnVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarActionPerformed(evt);
            }
        });

        jPanelInterno.setBackground(new java.awt.Color(204, 204, 255));

        lblCompromisso.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCompromisso.setText("Compromisso:");

        lblDia.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblDia.setText("Dia:");

        lblHora.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblHora.setText("Hora:");

        lblAno.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblAno.setText("Ano:");

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unipampa/icons/saveImg.png"))); // NOI18N
        btnSalvar.setToolTipText("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        lblMes.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblMes.setText("Mês:");

        lblRecebeHora.setText("<hora>");

        lblRecebeAno.setText("2013");

        lblRecebeDia.setText("<data>");

        lblRecebeMes.setText("<mes>");

        javax.swing.GroupLayout jPanelInternoLayout = new javax.swing.GroupLayout(jPanelInterno);
        jPanelInterno.setLayout(jPanelInternoLayout);
        jPanelInternoLayout.setHorizontalGroup(
            jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInternoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelInternoLayout.createSequentialGroup()
                        .addComponent(lblCompromisso)
                        .addGap(18, 18, 18)
                        .addComponent(txtCompromisso))
                    .addGroup(jPanelInternoLayout.createSequentialGroup()
                        .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelInternoLayout.createSequentialGroup()
                                .addComponent(lblAno)
                                .addGap(18, 18, 18)
                                .addComponent(lblRecebeAno))
                            .addGroup(jPanelInternoLayout.createSequentialGroup()
                                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblHora)
                                    .addComponent(lblDia)
                                    .addComponent(lblMes))
                                .addGap(18, 18, 18)
                                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblRecebeMes)
                                    .addComponent(lblRecebeHora)
                                    .addComponent(lblRecebeDia)))
                            .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 403, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelInternoLayout.setVerticalGroup(
            jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInternoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCompromisso)
                    .addComponent(txtCompromisso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblHora)
                    .addComponent(lblRecebeHora))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDia)
                    .addComponent(lblRecebeDia))
                .addGap(16, 16, 16)
                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMes)
                    .addComponent(lblRecebeMes))
                .addGap(13, 13, 13)
                .addGroup(jPanelInternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAno)
                    .addComponent(lblRecebeAno))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jPanelInterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanelInterno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarActionPerformed
        efeitoSonoro();
        EdicaoDeCompromisso.this.dispose();
    }//GEN-LAST:event_btnVoltarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        efeitoSonoro();
        if (verificaCampos()) {
            String tarefas = txtCompromisso.getText();
            //TRATANDO DIA
            String diaTxt = String.valueOf(lblRecebeDia.getText().toString());
            int diaInteger = Integer.parseInt(diaTxt);
            //TRATANDO HORA
            String horaTxt = lblRecebeHora.getText().toString();
            //TRATANDO ANO
            String anoTxt = lblRecebeAno.getText().toString();
            //TRATANDO MES
            String mesTxt = lblRecebeMes.getText().toString();

            this.date = new Data(diaInteger, mesTxt, anoTxt, horaTxt, tarefas);
            if (this.date.atualizarDados()) {
                ApoioDeInterface.mensagemDeSucesso();
                TrataAlarme.getInstance().alterarCompromisso(horaTxt, tarefas);
                EdicaoDeCompromisso.this.dispose();
            }
        }
    }//GEN-LAST:event_btnSalvarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSalvar;
    private javax.swing.JButton btnVoltar;
    private javax.swing.JPanel jPanelInterno;
    private javax.swing.JLabel lblAno;
    private javax.swing.JLabel lblCompromisso;
    private javax.swing.JLabel lblDia;
    private javax.swing.JLabel lblHora;
    private javax.swing.JLabel lblMes;
    private javax.swing.JLabel lblRecebeAno;
    private javax.swing.JLabel lblRecebeDia;
    private javax.swing.JLabel lblRecebeHora;
    private javax.swing.JLabel lblRecebeMes;
    private javax.swing.JTextField txtCompromisso;
    // End of variables declaration//GEN-END:variables

    @Override
    public boolean verificaCampos() {
        if (txtCompromisso.getText() != null
                || !txtCompromisso.getText().isEmpty()) {
            return true;
        } else {
            return false;
        }
    }
     @Override
    public void tratarIcone() {
        //definindo icone do sistema
        this.iconeTitulo= Toolkit.getDefaultToolkit().getImage(
                getClass().getResource("/br/unipampa/icons/iconeOfSystem.png"));
        
        this.setIconImage(this.iconeTitulo);
    }

    /**
     * @return the lblRecebeAno
     */
    public javax.swing.JLabel getLblRecebeAno() {
        return lblRecebeAno;
    }

    /**
     * @return the lblRecebeHora
     */
    public javax.swing.JLabel getLblRecebeHora() {
        return lblRecebeHora;
    }

    /**
     * @return the lblRecebeDia
     */
    public javax.swing.JLabel getLblRecebeDia() {
        return lblRecebeDia;
    }

    /**
     * @return the lblRecebeMes
     */
    public javax.swing.JLabel getLblRecebeMes() {
        return lblRecebeMes;
    }

    @Override
    public void efeitoSonoro() {
        ExecutaSom exeSound= new ExecutaSom();
        exeSound.executar("/br/unipampa/sounds/click1.wav");
    }

}